export default {
	data() {
		return {
			passShow: true,
			phone: '',
			code: '',
			password: '',
			codeMsg:'获取验证码',
			showModal:false,
			showContent:'',
			canconfirm:false
		}
	},
	methods: {
		phoneBlur() {
			//手机正则表达式
			let phoneCode = /^1[3456789]\d{9}$/;
			if (!(phoneCode.test(this.phone))) {
				uni.showToast({
					title:'请输入正确的手机号',
					icon:'none'
				})
				return
			}
		},
		codeBlur() {
			if(this.code == '') {
				uni.showToast({
					title:'验证码不能为空',
					icon:'none'
				})
				return
			}
		},
		passwordBlur() {
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/;
			if (!(passCode.test(this.password))) {
				this.showModal = true
				this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				this.canconfirm = false
				return;
			}
		},
		// 发送验证码
		sendCode() {
			let _this = this
			if(_this.isSend){
				return;
			}
			//手机正则表达式
			let phoneCode = /^1[3456789]\d{9}$/
			if(_this.phone == '' || !(phoneCode.test(_this.phone))){
				uni.showToast({
					title:'请输入正确的手机号',
					icon:'none'
				})
				return;
			}
			_this.$api.sedNote(_this.phone,'Modify').then((res)=>{
				if (!_this.timer) {
					_this.count = 60;
					_this.isSend = true;
					_this.timer = setInterval(() => {
						if (_this.count > 0 && _this.count <= 60) {
							_this.codeMsg = _this.count+'s'
							_this.count--;
						} else {
							_this.codeMsg = '获取验证码'
							clearInterval(_this.timer);
							_this.isSend = false;
							_this.timer = null;
						}
					}, 1000)
				}
			})
		},
		confirm() {
			let _this = this
			let phoneCode = /^1[3456789]\d{9}$/
			//密码正则表达式
			let passCode = /(?!.*\s)(?!^[\u4E00-\u9FA5]+$)(?!^[a-zA-Z]+$)(?!^[\d]+$)(?!^[^\u4E00-\u9FA5a-zA-Z\d]+$)^.{6,20}$/
			if (!(phoneCode.test(_this.phone))) {
				uni.showToast({
					title:'请输入正确的手机号',
					icon:'none'
				})
				return;
			}
			if (_this.code == '') {
				uni.showToast({
					title:'验证码不能为空',
					icon:'none'
				})
				return;
			}
			if (!(passCode.test(_this.password))) {
				_this.showModal = true
				_this.showContent = '密码不少于6位数，且字母、数字和符号至少包含两种。'
				_this.canconfirm = false
				return;
			}
			const userRegisterReq = {
				code: _this.code,
				password: _this.password,
				phone: _this.phone
			}
			this.$api.resetPassword(userRegisterReq).then((res) => {
				if(res.data.returnCode == 200){
					_this.showModal = true
					_this.showContent = '重置成功'
					_this.canconfirm = true
				}else{
					_this.showModal = true
					_this.showContent = res.data.message
					_this.canconfirm = false
				}
			})
		},
		Modalconfim(){
			if(this.canconfirm){
				uni.navigateTo({
					url:'/pages/login/login'
				})
			}
		}
	}
}